package org.walkframework.apps.test.business.base;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.walkframework.boot.ehdb.dao.StaticDAO;
import org.walkframework.boot.ehdb.util.ScriptRunner;

import java.io.InputStreamReader;
import java.util.Objects;

/**
 * 初始化sql，已废弃，交由数据库自动升级能力实现，见<code>SampleMetaAutoUpgradeConfig</code>
 *
 * @author 尾生
 * @since 2024/4/9
 */
@RunWith(SpringRunner.class)
@SpringBootTest
@Deprecated
public class InitSql {

    @Autowired
    private StaticDAO baseStaticDAO;
    @Test
    public void initSql() {
        ScriptRunner scriptRunner = new ScriptRunner(baseStaticDAO.getDatasource());
        // 此处还可以配置是否使用事务等
        scriptRunner.runScript(new InputStreamReader(Objects.requireNonNull(
                this.getClass().getResourceAsStream("/sql/sample/mysql/init-1.0.0/1.0.0.sql"))));
    }
}
